package com.zxcl.money.handler;

import com.zxcl.model.OrderMoneyContext;
import com.zxcl.money.CalculateAmount;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;

import java.math.BigDecimal;
import java.util.List;
/**
 * 描述: [优惠券金额处理]
 * 作者: zxcl
 */
@Component("couponMoneyHandler")
public class CouponMoneyHandler extends CalculateAmount {

    // 根据用户的id 查询对应的优惠券  默认券 可以先算起来

    @Override
    public void calculate(OrderMoneyContext orderMoneyContext) {
        List<Long> couponIds = orderMoneyContext.getCouponIds();
        if (!CollectionUtils.isEmpty(couponIds)) {
            // 查对应优惠券的信息 计算金额
        } else {
            orderMoneyContext.setCouponMoney(BigDecimal.ZERO);
        }
        // 执行下一个责任链
        CalculateAmount nextHandler = getNextHandler();
        if (!ObjectUtils.isEmpty(nextHandler)) {
            nextHandler.calculate(orderMoneyContext);
        }
    }
}
